/*
 * License: Copyright (c) Huawei Technologies Co., Ltd. 2012-2019. All rights reserved.
 * Description: convertion between string and number 
 * Date: 2019-12-02 16:11:28
 * LastEditTime : 2019-12-30 18:35:58
 */

#ifndef STR_NUM_H
#define STR_NUM_H

#include <sstream>
#include <string>

using namespace std;

const int g_strNumErr = -9999;

bool IsDigit(const string param)
{
    for (auto a : param) {
        if (!isdigit(a)) {
            return false;
        }
    }

    return true;
}

int str2num(const string str)
{
    bool res = IsDigit(str);
    if (!res) {
        return g_strNumErr;
    }
    
    stringstream ss;
    ss << str;
    int num;
    ss >> num;

    return num;
}

string num2str(const int num)
{
    stringstream ss;
    ss << num;
    string str;
    ss >> str;

    return str;
}



#endif // STR_NUM_H
